package com.qin.entity;

import com.qin.service.ExecuteService;
import com.qin.service.TestCaseService;
import com.qin.service.impl.ExecuteServiceImpl;
import com.qin.service.impl.TestCaseServiceImpl;
import lombok.Data;
import java.util.List;

@Data
public class TestCase {

    //主键
    private String testcase_id;
    //所属公共函数id
    private String function_id;
    //序号
    private int order_number;
    //案例名称
    private String case_name;
    //是否执行（0-否，1-是）
    private int is_used;

    private List<Component> componentList;

    private ExecuteService executeService = new ExecuteServiceImpl();

    public void execute(ExecuteBean executeBean){
        //补全本TestCase对象的各属性
        this.complete();
        //设置ExecuteBean对象的各属性
        executeBean.setTestcase_id(testcase_id);
        //设置ExecuteLog对象的各属性
        ExecuteLog executeLog = new ExecuteLog(executeBean.getExecute_id(), executeBean.getFunction_id(),
                executeBean.getTestcase_id(), "", "", "");
        //插入日志
        executeService.insertExecuteLog(executeLog, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>案例【" + case_name + "】执行开始");

        //执行组件的execute方法
        if(componentList != null){
            for (int i=0; i<componentList.size(); i++){
                componentList.get(i).execute(executeBean);
            }
        }
        //插入日志
        executeService.insertExecuteLog(executeLog, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>案例【" + case_name + "】执行结束");
    }

    public void complete(){
        //补全本TestCase对象的各属性
        TestCaseService testCaseService = new TestCaseServiceImpl();
        TestCase testCase = testCaseService.queryTestCaseByTestCaseId(this);

        this.setTestcase_id(testCase.testcase_id);
        this.setFunction_id(testCase.function_id);
        this.setOrder_number(testCase.order_number);
        this.setCase_name(testCase.case_name);
        this.setIs_used(testCase.is_used);

        this.setComponentList(testCase.getComponentList());
    }
}